package com.sunwayworld.basemodule.common.eptstorage.db.service.impl;

import com.sunwayworld.basemodule.common.eptstorage.db.bean.LimsDbextractConfigBean;
import com.sunwayworld.basemodule.common.eptstorage.db.dao.LimsDbextractConfigDao;
import com.sunwayworld.basemodule.common.eptstorage.db.service.LimsDbextractConfigService;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@GikamBean
public class LimsDbextractConfigServiceImpl implements LimsDbextractConfigService {

    @Autowired
    private LimsDbextractConfigDao limsDbextractConfigDao;

    @Override
    @SuppressWarnings("unchecked")
    public LimsDbextractConfigDao getDao() {
        return limsDbextractConfigDao;
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        LimsDbextractConfigBean limsDbextractConfig = jsonWrapper.parseUnique(LimsDbextractConfigBean.class);
        limsDbextractConfig.setId(ApplicationContextHelper.getNextIdentity());
        getDao().insert(limsDbextractConfig);
        return limsDbextractConfig.getId();
    }

}
